﻿using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading.Tasks;

namespace System
{
    public class CmdHelper
    {
        public static Process ExecuteCmd(string command, EventHandler eventHandler = null)
        {
            if (!string.IsNullOrEmpty(command))
            {
                var process = new Process();
                var startInfo = new ProcessStartInfo();
                startInfo.FileName = "cmd.exe";
                startInfo.Arguments = "/C " + command;//表示执行完命令后马上退出     
                process.StartInfo = startInfo;
                process.EnableRaisingEvents = true;
                if (eventHandler != null)
                {
                    process.Exited += eventHandler;
                }
                process.Start();
                return process;
            }
            return null;
        }
    }
}
